package com.gagakuai.transport.channel.socket.nio;

import com.gagakuai.transport.channel.AbstractChannel;
import com.gagakuai.transport.channel.Channel;

import java.io.IOException;
import java.nio.channels.SelectableChannel;

/*
 * @description: nio的信道抽象
 * @author: houhong
 * @create: 2024-03-30 11:32
 */
public abstract class AbstractNioChannel extends AbstractChannel {


    final SelectableChannel ch;

    protected final int readInterestOp;

    protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) {

        super(parent);

        this.ch = ch;

        //将channel 感兴趣的事件类型设置到当前属性
        this.readInterestOp = readInterestOp;


        try {
            //将当前到nioServerSocket 设置为非阻塞
            ch.configureBlocking(false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
